Skip to content

Conversation

@mxz297
Copy link
Contributor

@mxz297 mxz297 commented Aug 11, 2025

Current AITER attention for prefill incurs one D2H copy (which causes synchonrization between CPU and GPU) and one cumsum kernel.
Screenshot 2025-08-11 at 3 48 28 PM

The D2H copy is used to get the actual KV tokens on the host side for intermediate buffer allocation; this value should not change during the inference, so we can pre-compute it during AttentionMetadata construction time. And similarly, the cumsum kernel can be done in AttentionMedata construction time

Screenshot 2025-08-11 at 3 49 47 PM

We can see there is memcpy and gpu bubbles after the change.

Saw about 10% prefill latency improvement

Essential Elements of an Effective PR Description Checklist

  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

Purpose

Test Plan

Test Result

(Optional) Documentation Update

Current AITER attention for prefill incurs one D2H copy (which causes
synchonrization between CPU and GPU) and one cumsum kernel.

The D2H copy is used to get the actual KV tokens on the host side for
intermediate buffer allocation; this value should not change during the
inference, so we can pre-compute it during AttentionMetadata construction
time. And similarly, the cumsum kernel can be done in AttentionMedata
construction time

Signed-off-by: Xiaozhu <[email protected]>
@github-actions
Copy link

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

@mergify mergify bot added rocm Related to AMD ROCm v1 labels Aug 11, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to optimize the AITER attention backend for prefill on ROCm by avoiding a device-to-host copy and a redundant cumsum kernel execution. The changes achieve this by pre-computing cu_seq_lens and num_actual_kv_tokens during the AttentionMetadata construction, which is a sound optimization strategy.

My review includes a suggestion to correct a type hint for the newly added cu_seq_lens attribute.

Additionally, I've identified a potential critical issue in the AiterFlashAttentionImpl.forward method. It appears that for prefill requests, both the prefill attention kernel (flash_attn_varlen_func) and the decode attention kernel (paged_attention_v1) are called sequentially. This would cause the output of the prefill kernel to be overwritten by the decode kernel, likely resulting in incorrect outputs and performance degradation. I strongly recommend wrapping the decode kernel call in an else block to ensure it's only executed for decode requests. While this issue pre-exists this PR, it is critical to fix for the backend to function correctly.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Michael Goin <[email protected]>
Copy link
Member

@mgoin mgoin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice find!

@mgoin mgoin enabled auto-merge (squash) August 12, 2025 01:20
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 12, 2025
Copy link
Collaborator

@HAIAI HAIAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some question on a new meta data introduced.

@mxz297
Copy link
Contributor Author

mxz297 commented Aug 12, 2025

@HAIAI @mgoin First PR to vllm oss, so not quite sure about the CIs results.

It looks to me tpu tests are not related?

the v1-test failure says

ValueError: Free memory on device (8.42/22.05 GiB) on startup is less than desired GPU memory utilization (0.9, 19.84 GiB). Decrease GPU memory utilization or reduce GPU memory used by other processes.

but seems like it is on NV platform, for which my pr should have no impact...

Can you give some advice on the CI failures?

@mgoin
Copy link
Member

mgoin commented Aug 12, 2025

Hi @mxz297 unfortunately the CI has lots of failures at the moment, we usually try to keep it in a better state. Please ignore these for now and I will request force merge.

@mgoin mgoin added performance Performance-related issues force-merge labels Aug 12, 2025
@simon-mo simon-mo disabled auto-merge August 12, 2025 19:53
@simon-mo simon-mo merged commit 6bd8ebf into vllm-project:main Aug 12, 2025
44 of 51 checks passed
diegocastanibm pushed a commit to diegocastanibm/vllm that referenced this pull request Aug 15, 2025
Signed-off-by: Xiaozhu <[email protected]>
Signed-off-by: Michael Goin <[email protected]>
Co-authored-by: Michael Goin <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Diego-Castan <[email protected]>
yiliu30 pushed a commit to yiliu30/vllm-fork that referenced this pull request Aug 19, 2025
Signed-off-by: Xiaozhu <[email protected]>
Signed-off-by: Michael Goin <[email protected]>
Co-authored-by: Michael Goin <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
divakar-amd pushed a commit to divakar-amd/vllm_upstream that referenced this pull request Aug 20, 2025
Signed-off-by: Xiaozhu <[email protected]>
Signed-off-by: Michael Goin <[email protected]>
Co-authored-by: Michael Goin <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@fsx950223
Copy link
Contributor

The PR breaks full graph mode.

@ProExpertProg
Copy link
Collaborator

@fsx950223 could you file an issue for it please?

epwalsh pushed a commit to epwalsh/vllm that referenced this pull request Aug 28, 2025
Signed-off-by: Xiaozhu <[email protected]>
Signed-off-by: Michael Goin <[email protected]>
Co-authored-by: Michael Goin <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
xiao-llm pushed a commit to xiao-llm/vllm that referenced this pull request Aug 28, 2025
Signed-off-by: Xiaozhu <[email protected]>
Signed-off-by: Michael Goin <[email protected]>
Co-authored-by: Michael Goin <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Xiao Yu <[email protected]>
zhewenl pushed a commit to zhewenl/vllm that referenced this pull request Aug 28, 2025
Signed-off-by: Xiaozhu <[email protected]>
Signed-off-by: Michael Goin <[email protected]>
Co-authored-by: Michael Goin <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

force-merge performance Performance-related issues ready ONLY add when PR is ready to merge/full CI is needed rocm Related to AMD ROCm v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants